<?php

    $slidewindows = new MikronSlideWindow();
    $mikron->OperatingInstructions->AddFunction('slidewindow', 'OperatingInstruction_SlideWindow', $slidewindows);
    $mikron->OperatingInstructions->AddFunction('/slidewindow', 'OperatingInstruction_SlideWindowClose', $slidewindows);
    $mikron->CSS->AddFile(dirname(__FILE__).'/style.css', 'Стиль модуля UpVoting');

    /**
    * Sample/Пример:
    * {{slidewindow caption="Контакты" showtext="Редактировать" hidetext="Скрыть" load="/1.php"}}
    * load - адрес, откуда возьмется контент используя AJAX
    */

    class MikronSlideWindow
    {
        private $id = Array();
        function OperatingInstruction_SlideWindow($parameters)
        {
            global $mikron;
            $unqid = 'sw_'.md5(time().mt_rand(0,999999).mt_rand(0,999999));
            $this->id[] = $unqid;
            $caption = $parameters['caption'];
            $showtext = $mikron->Tools->GetParam($parameters, 'showtext', 'Показать');
            $hidetext = $mikron->Tools->GetParam($parameters, 'hidetext', 'Скрыть');
            $load = $mikron->Tools->GetParam($parameters, 'load', null);
            $comment = $mikron->Tools->GetParam($parameters, 'comment', null);
            ?><table class="mikron_slidewindow_window" width="100%" cellspacing="0" cellpadding="0">
            <tr class="mikron_slidewindow_caption">
                <td class="mikron_slidewindow_caption_text"><?php echo $caption; ?>
                <?php if(!$mikron->Tools->IsNullOrEmpty($comment)) { ?><br /><span class="simple_font"><?php echo $comment; ?></span><?php } ?>
                </td>
                <td class="mikron_slidewindow_button_cell">
                <script type="text/javascript">
                    var loaded_<?php echo $unqid;?> = false;
                    function toogle_slidewindow_<?php echo $unqid;?>(object)
                    {
                        object.innerText = ($('#<?php echo $unqid;?>').css('display')=='none')?'<?php echo $hidetext;?>':'<?php echo $showtext;?>';
                        $('#<?php echo $unqid;?>').slideToggle('fast');
                    }
                    function f_slidewindow_<?php echo $unqid;?>(object)
                    {
                        <?php if(!is_null($load)) {
                            ?>
                            if(loaded_<?php echo $unqid;?>)
                            {
                                toogle_slidewindow_<?php echo $unqid;?>(object);
                            }                 
                            else
                            {
                                object.style.display = 'none';
                                $('#ajax_loader_<?php echo $unqid;?>').css('display','');
                                $('#<?php echo $unqid;?>_area').load('<?php echo $load; ?>', { formName : 'formname' },
                                function()
                                { object.style.display = '';
                                  $('#ajax_loader_<?php echo $unqid;?>').css('display','none');
                                  toogle_slidewindow_<?php echo $unqid;?>(object);
                                  loaded_<?php echo $unqid;?> = true; });
                            }
                            <?php
                        } else { ?>
                            toogle_slidewindow_<?php echo $unqid;?>(object);
                        <?php }?>
                        return false;
                    }
                </script>
                <table cellpadding="0" cellspacing="0" align="right">
                    <tr><td style="height: 19px; ">
                        <a onclick="return f_slidewindow_<?php echo $unqid;?>(this);"
                        title="<?php echo $showtext; ?>" href="#"><?php echo $showtext; ?></a>
                    </td>
                    <td>
                        <img id="ajax_loader_<?php echo $unqid;?>" style="display: none; " src="/templates/main/images/ajax-loader.gif" alt="ajax-loader" />
                    </td>
                    </tr>
                </table>
            </td>
            </tr>
            <tr>
            <td colspan="2" style="padding: 0 .5em .0em .5em;">
                <div id="<?php echo $unqid; ?>" style="display: none; ">
                <div id="<?php echo $unqid; ?>_area" style="padding: .5em 0 .5em 0;">
            <?php
        }

        function OperatingInstruction_SlideWindowClose($parameters)
        {
            ?></div></div></td></tr></table><?php
        }

    }

?>